<?

$_values = array('id', 'id_index', 'attr', 'assoc', 'name', 'value', 'text', 'tag');

if (($c = $DATA['component']) && $c['id']) {

	$__settings = datafetch_array('db_list', array('table' => tb('data'), 
		'where' => "id_parent = $c[id] AND id_data=".D_MB_SETTINGS, 'index' => 'name'));

	$__path = FP_UPLOAD_PATH.$__settings['path']['value'].'/';

	$__data = datafetch_array('db_list', array('table' => tb('data'), 
		'where' => "id_parent = $c[id] AND id_data=".D_MB_DATA, 'index' => 'id'));
		
	$__meta = datafetch_array('db_list', array('table' => tb('data'), 
		'where' => "id_parent in (".implode(',', array_keys($__data)).") AND id_data=".D_MB_META, 'index' => 'id'));

	foreach($__meta as $id => $v)
		if (isset($__data[$v['id_parent']]))
			$__data[$v['id_parent']]['meta'][] = $v;



	$e['root']->appendChild($s = $e['document']->createElement('settings'));
	
	foreach($__settings as $id => $v) {
		$s->appendChild($x = $e['document']->createElement('set'));
		foreach($_values as $key)
			$x->setAttribute($key, $v[$key]);
	}

	$e['root']->appendChild($s = $e['document']->createElement('content'));

	foreach($__data as $id => $v) {
		$s->appendChild($x = $e['document']->createElement('data'));
		foreach($_values as $key)
			$x->setAttribute($key, $v[$key]);
			
		if (isset($v['meta']))
			foreach($v['meta'] as $meta) {
				$x->appendChild($m = $e['document']->createElement('meta'));
				foreach($_values as $key)
					$m->setAttribute($key, $meta[$key]);
			}

		if ($im = isImage($__path, $id)) {
			
			$fn = parse_fname($im);
			$x->setAttribute("image", '<id>.'.$fn['ext']);

			$e['attach'][] = array('archName' => $im, 'fName' => $_SERVER['DOCUMENT_ROOT']."$__path$im");
		}
			
	}

	return false;
} else exit;


